package cxm.lib.sys;

import cxm.lib.util.MyLog;

public abstract class StartMachine {
	public class StartMachineException extends Exception {
		/**
		 * 
		 */
		private static final long serialVersionUID = -8949452574123010518L;

		public StartMachineException(String msg) {
			super("StartMachineException: " + msg);
		}
	}
	
	private boolean isStart = false;
	
	public void start() throws StartMachineException {
		if (isStart)
			throw new StartMachineException("Already start");
		
		this.onStart();
		this.isStart = true;
	}
	
	public void stop() {
		if (!this.isStart) {
			MyLog.Log(MyLog.Level.Warning, "Already Stop");
			return;
		}
		
		this.onStop();
		this.isStart = false;
	}
	
	public boolean isStart() {
		return this.isStart;
	}
	
	protected abstract void onStart() throws StartMachineException;
	
	protected abstract void onStop();
}
